package com.lincoln.cloud.servercenter.abstracter;

import com.lincoln.cloud.common.bean.ServerMessage;
import com.lincoln.cloud.servercenter.interfaces.BaseServerInfo;
import com.lincoln.cloud.servercenter.interfaces.ServerPool;
import com.lincoln.cloud.servercenter.interfaces.ServerPoolContainer;

import java.util.List;

/**
 * 默认的int为id的服务器池实现
 *
 * @author lincoln
 */
public class IntServerPool implements ServerPool {
    /**
     * 主键
     */
    private static int id = 0;
    /**
     * 容器
     */
    private ServerPoolContainer serverPoolContainer;

    public IntServerPool() {
        setContainer(new MapServerPoolContainer());
    }

    @Override
    public boolean setContainer(ServerPoolContainer serverPoolContainer) {
        this.serverPoolContainer = serverPoolContainer;
        return true;
    }

    @Override
    public ServerPoolContainer getContainer() {
        return serverPoolContainer;
    }

    @Override
    public synchronized int createId() {
        return id++;
    }

    @Override
    public BaseServerInfo findById(int id) {
        return serverPoolContainer.findById(id);
    }

    @Override
    public List<BaseServerInfo> findByName(String name) {
        return serverPoolContainer.findByName(name);
    }

    @Override
    public List<BaseServerInfo> findAll() {
        return serverPoolContainer.findAll();
    }

    @Override
    public boolean addServer(BaseServerInfo serverInfo) {
        return serverPoolContainer.addServer(serverInfo);
    }

    @Override
    public boolean deleteServer(int id) {
        return serverPoolContainer.deleteServer(id);
    }

    @Override
    public boolean deleteServer(String name) {
        return serverPoolContainer.deleteServer(name);
    }

    @Override
    public void dealServerMessage(ServerMessage serverMessage) {

    }

    @Override
    public boolean sendServerMessage(ServerMessage serverMessage) {
        return true;
    }
}
